<template>
  <div v-if="routeName === 'Export'" class="list-page">
    <div class="block-wrap filter-form">
      <el-form :inline="true" :model="form" size="small" label-width="140px">
        <!-- <el-form-item>
          <el-select
            slot="label"
            v-model="form.type"
            style="width: 120px"
            placeholder="所属区域"
          >
            <el-option value="1">长沙</el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item>
          <el-select
            slot="label"
            v-model="form.state"
            style="width: 120px"
            placeholder="状态"
          >
            <el-option value="0" label="未导出">未导出</el-option>
            <el-option value="1" label="已导出">已导出</el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="项目名称:">
          <el-input placeholder="请输入" v-model="form.projectname" />
        </el-form-item>
        <el-form-item label="坐落:">
          <el-input placeholder="请输入" v-model="form.zl" />
        </el-form-item>
        <el-form-item label="特别号:">
          <el-input placeholder="请输入" v-model="form.tbh" />
        </el-form-item>
        <el-form-item class="filter-form-btns">
          <el-button type="primary" @click="search">查询</el-button>
          <el-button type="default" @click="resetForm">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="block-wrap">
      <el-table
        :data="dataList"
        style="width: 100%;"
        align="center"
        header-align="center"
        :header-cell-style="headerStyle"
        :cell-style="cellStyle"
        v-loading="loading"
      >
        <el-table-column
          type="index"
          label="序号"
          width="60"
          :index="getIndex"
        />
        <el-table-column prop="projectname" label="项目名称" />
        <el-table-column prop="housenum" label="幢编号">
          <template slot-scope="scope">
            <el-button type="text" @click="handleHouseDetail(scope.row)">{{
              scope.row.housenum
            }}</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="earthnum" label="特别号" />
        <el-table-column prop="frRegion" label="所属区域" />
        <el-table-column prop="bstruct" label="结构">
          <template slot-scope="scope">
            {{ getBstruct(scope.row.bstruct) }}
          </template>
        </el-table-column>
        <el-table-column prop="bdesignuse" label="用途" />
        <el-table-column prop="address" label="坐落" />
        <el-table-column prop="status" label="状态">
          <template slot-scope="scope">
            <div class="statusInfo">
              <i
                class="statusCircular"
                :class="scope.row.status === '1' ? 'export' : 'notExport'"
              ></i>
              <span>{{ scope.row.status === "1" ? "已导出" : "未导出" }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="options" label="操作">
          <template slot-scope="scope">
            <el-button type="text" @click="exportFile(scope.row)"
              >导出</el-button
            >
            <el-button type="text" @click="handleDetail(scope.row)"
              >查看详情</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-size="form.size"
        :page-sizes="[10, 20, 30, 40]"
        layout="total, prev, pager, next, sizes, jumper"
        :total="total"
      />
    </div>
    <el-dialog
      title="幢详情"
      :visible.sync="dialogVisible"
      width="1016px"
      :close-on-click-modal="false"
    >
      <el-descriptions :column="2" border :colon="false" size="medium">
        <el-descriptions-item label="幢号:">{{
          houseInfo.housenum
        }}</el-descriptions-item>
        <el-descriptions-item label="小区名称:">{{
          houseInfo.rqname
        }}</el-descriptions-item>
        <el-descriptions-item label="项目名称:">{{
          houseInfo.projectname
        }}</el-descriptions-item>
        <el-descriptions-item label="街路巷:">{{
          houseInfo.road
        }}</el-descriptions-item>
        <el-descriptions-item label="门牌号:">{{
          houseInfo.doorno
        }}</el-descriptions-item>
        <el-descriptions-item label="坐落:">{{
          houseInfo.bsit
        }}</el-descriptions-item>
        <el-descriptions-item label="占地面积:">{{
          houseInfo.earea
        }}</el-descriptions-item>
        <el-descriptions-item label="建筑面积:">{{
          houseInfo.barea
        }}</el-descriptions-item>
        <el-descriptions-item label="套内建筑面积:">{{
          houseInfo.rarea
        }}</el-descriptions-item>
        <el-descriptions-item label="房屋结构:"></el-descriptions-item>
        <el-descriptions-item label="建筑结构:">{{
          houseInfo.bstruct
        }}</el-descriptions-item>
        <el-descriptions-item label="建筑用途:">{{
          houseInfo.bdesignuse
        }}</el-descriptions-item>
        <el-descriptions-item label="测绘状态:">{{
          houseInfo.accepted
        }}</el-descriptions-item>
        <el-descriptions-item label="幢来源:">测绘</el-descriptions-item>
        <el-descriptions-item label="总套数:"></el-descriptions-item>
        <el-descriptions-item label="住宅套数:">{{
          houseInfo.dwrooms
        }}</el-descriptions-item>
        <el-descriptions-item label="总层数:">{{
          houseInfo.ttlflrs
        }}</el-descriptions-item>
        <el-descriptions-item label="地上层数:">{{
          houseInfo.underflrs
        }}</el-descriptions-item>
        <el-descriptions-item label="街道:">{{
          houseInfo.street
        }}</el-descriptions-item>
        <el-descriptions-item label="街坊:">{{
          houseInfo.community
        }}</el-descriptions-item>
        <el-descriptions-item label="单元总数:"></el-descriptions-item>
        <el-descriptions-item label="住宅面积:">{{
          houseInfo.dwarea
        }}</el-descriptions-item>
        <el-descriptions-item label="东至:">{{
          houseInfo.east
        }}</el-descriptions-item>
        <el-descriptions-item label="南至:">{{
          houseInfo.south
        }}</el-descriptions-item>
        <el-descriptions-item label="西至:">{{
          houseInfo.west
        }}</el-descriptions-item>
        <el-descriptions-item label="北至:">{{
          houseInfo.north
        }}</el-descriptions-item>
        <el-descriptions-item label="竣工日期:">{{
          houseInfo.fnshdate
        }}</el-descriptions-item>
        <el-descriptions-item label="栋号:">{{
          houseInfo.housenum
        }}</el-descriptions-item>
      </el-descriptions>
      <span slot="footer" class="dialog-footer">
        <!-- <el-button type="primary" @click.stop="handleCloseDialog"
          >关 闭</el-button
        > -->
      </span>
    </el-dialog>
    <!-- <el-dialog
      title="幢详情"
      :visible.sync="dialogVisible"
      width="34%"
      :close-on-click-modal="false"
    >
    </el-dialog> -->
    <div class="footer">
      Copyright © 2018-2020 湖南智慧政务区块链科技有限公司
    </div>
  </div>
  <router-view v-else :key="key" />
</template>

<script>
import { getForecastList, getHouseInfo } from "@/api/propertiesInfo";
import DOWNLOAD from "@/api/dowFile";
export default {
  name: "Properties",
  data() {
    return {
      form: {
        state: "",
        projectname: "",
        zl: "",
        tbh: "",
        page: 1,
        limit: 10
      },
      dataList: [],
      total: 0,
      dialogVisible: false,
      houseInfo: {},
      statusCircularStyle: "notExport",
      loading: false
    };
  },
  computed: {
    key() {
      return this.$route.path;
    },
    routeName() {
      return this.$route.name;
    }
  },
  created() {
    this.getForecastList();
  },
  methods: {
    getForecastList() {
      this.loading = true;
      getForecastList(this.form)
        .then(res => {
          this.dataList = res.data.list;
          this.total = res.data.count;
          this.loading = false;
        })
        .catch(() => {
          this.loading = false;
        });
    },
    search() {
      this.getForecastList();
    },
    handleSizeChange(val) {
      this.form.size = val;
      this.getForecastList();
    },
    handleCurrentChange(val) {
      this.form.page = val;
      this.getForecastList();
    },
    exportFile(row) {
      this.exprotFileParams(row.projectid);
    },
    exprotFileParams(projectid) {
      const download = new DOWNLOAD();
      download.exportExcel("/exportExcel", { projectid: projectid });
      this.getForecastList();
    },
    getBstruct(row) {
      switch (row) {
        case "1":
          return "钢结构";
        case "2":
          return "钢和钢筋混凝土结构";
        case "3":
          return "钢筋混凝土结构";
        case "4":
          return "混合结构";
        case "5":
          return "砖木结构";
        case "6":
          return "其它结构";
      }
    },
    resetForm() {
      this.form = {
        state: "",
        projectname: "",
        zl: "",
        tbh: "",
        page: 1,
        limit: 10
      };
      this.getForecastList();
    },
    handleDetail(row) {
      this.$router.push({
        name: "PropertieDetail",
        query: { housenum: row.housenum }
      });
    },
    async handleHouseDetail(row) {
      const data = await getHouseInfo(row.housenum);
      this.houseInfo = data.data;
      this.dialogVisible = true;
    },
    handleCloseDialog() {
      this.dialogVisible = false;
    },
    headerStyle() {
      return {
        background: "#F5F9FF",
        color: "#2E2E30"
      };
    },
    cellStyle() {
      return {
        height: "48px",
        padding: "0"
      };
    },
    getIndex($index) {
      return $index + (this.form.page - 1) * this.form.limit + 1;
    }
  }
};
</script>

<style lang="scss">
@import "~@/styles/page/list-page.scss";
.block-wrap {
  padding: 25px;
  background: #fff;
  border-radius: 2px;
  margin-bottom: 16px;
}
.el-table .el-table__cell {
  text-align: center;
}
.el-button--text {
  min-width: 30px;
}
.el-descriptions {
  padding-top: 10px;
  .el-descriptions__header {
    color: red;
  }
  .el-descriptions-item__label {
    text-indent: 20px;
    font-weight: 600;
  }
  .el-descriptions-item__cell.el-descriptions-item__label.is-bordered-label {
    width: 150px;
    background: #f5f9ff;
    font-size: 14px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: rgba(0, 0, 0, 0.85);
  }
}
.el-dialog__header {
  border-bottom: 1px solid #eee;
}
.el-dialog__body {
  padding: 8px 20px;
  max-height: 618px;
  overflow-y: auto;
}
.el-dialog__title {
  font-weight: 800;
}
.el-button--text {
  color: #5892ff;
}
.statusInfo {
  display: flex;
  justify-content: center;
  align-items: center;
}
.statusCircular {
  width: 6px;
  height: 6px;
  display: inline-block;
  margin-right: 8px;
  border-radius: 50%;
}
.notExport {
  background-color: red;
}
.export {
  background-color: #52c41a;
}
.footer {
  text-align: center;
  margin-top: 50px;
  font-size: 12px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.45);
  line-height: 20px;
}
.el-pagination .btn-prev,
.el-pagination .btn-next,
.el-pagination .el-pager li {
  border: 1px solid #eee;
  margin-right: 8px;
}
.el-pager li.active + li {
  border-left: 1px solid #eee;
}
.el-pager li.active {
  border-color: #295ec8;
}
</style>
